package com.i2bt.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
 * 
 * Title : 判断网络访问工具
 *
 * Description : 判断现在有没有网络连接
 *
 * CreatedTime : 2014-8-12
 *
 * @author wuliao & kakaxi & yi
 *
 * @version 1.0
 *
 */
public class NetworkUtil {
	
	/**
	 * 是否有连接网络
	 * @param context 上下文
	 * @return
	 */
	public static boolean isNetworkConnection(Context context) {
		boolean isConnected = false;
		if (getNetworkInfo(context) != null) {
			isConnected = getNetworkInfo(context).isConnected();
		}
		return isConnected;
	}
	
	/**
	 * 获取网络配置类
	 * @param context 上下文
	 * @return
	 */
	public static NetworkInfo getNetworkInfo(Context context) {
		ConnectivityManager connManager = (ConnectivityManager) context.
				getSystemService(Context.CONNECTIVITY_SERVICE);
		return connManager.getActiveNetworkInfo();
	}
}
